import geoJSONLoader from "echarts/src/coord/geo/geoJSONLoader";

var stage = ''
var preload = ''
var canvas_scale = 1
import $ from "jquery";
import Swiper from 'swiper';
import './assets/css/reset.css';
import './assets/css/animation.css';
import './assets/css/cssfromps.css';
import './assets/css/css.css';
import createjs from 'createjs-cmd'


// import {CountUp} from 'countup.js';
import {fenxiang} from "./lib/fenxiang"

var jQuery = require("jquery-easing");

// import VConsole from 'vconsole/dist/vconsole.min.js' //import vconsole

let rem = document.documentElement.clientWidth / 750 * 100
let dheight = document.documentElement.clientHeight
let play_now = true;
let music_now = true;
let playused = false;


$(() => {
	loadAssest()
	initescroll()


	fenxiang("调查：我们身边的WIFI安全吗？黑灰产业链“挖”给你看", "新闻调查：我们身边的WIFI安全吗？这条黑灰产业链“挖”给你看\n", "调查：我们身边的WIFI安全吗？黑灰产业链“挖”给你看", '', "http://o.cztvcloud.com/181/5842406/images/fenxiang.jpg")
	init()
	setTimeout(() => {
		$('.loading').hide()
		$('.p1 .views').fadeIn()
	}, 1000)
	/*	var video = document.getElementById('video')
	   //必须在微信Weixin JSAPI的WeixinJSBridgeReady才能生效
	document.addEventListener("WeixinJSBridgeReady", function () {
		   document.getElementById("musics").load();

		   document.getElementById("musics").play();
	   }, false);
	   document.getElementById("musics").play();*/
	$(".music_play").click(function () {
		if (play_now) {
			$(".music_play").removeClass("music_pause");
			$(".music_play").addClass("music_pause");
			play_now = false;
			playused = false;
			$(".bgMusic")[0].pause();
			$(".music").attr("src", "https://o.cztvcloud.com/181/5842406/images/musicoff.png")
		} else {
			$(".music_play").removeClass("music_pause");
			play_now = true;
			playused = false;
			$(".bgMusic")[0].play();
			$(".music").attr("src", "https://o.cztvcloud.com/181/5842406/images/musicon.png")
		}
	});
	var userInsertInterval = null


})

// -----------------------------
function initescroll() {
	var documentHeight = 1448    //part1
	// var documentHeight = 8680     //part2
	// var documentHeight = 9470        //part3
	canvas_scale = 750 / 750;
	var rem = 750 / 750 * 100;
	var canvasWidth = 750;
	var canvasHeight = documentHeight;
	var endline = documentHeight - (750 / document.documentElement.clientWidth) * document.documentElement.clientHeight;
	// console.log(endline);
	var canvas = document.getElementById("canvas");
	canvas.width = canvasWidth
	//根据宽度计算出的高度。在满屏，没有滑动的情况下使用
	canvas.height = document.documentElement.clientHeight * (750 / document.documentElement.clientWidth);
	// canvas.height = document.documentElement.clientHeight;
	stage = new createjs.Stage('canvas');
	stage.regX = 0;
	stage.regY = 0
	var container = new createjs.Container();
	stage.addChild(container);
	stage.enableMouseOver()


	document.body.addEventListener('touchmove', function (e) {
		e.preventDefault();
	}, {passive: false}); //阻止默认的处理方式(阻止下拉滑动的效果) passive 参数不能省略，用来兼容ios和android

}

function loadAssest() {
	createjs.Ticker.setFPS(30);
	createjs.Ticker.addEventListener("tick", translateY)
	// 加载资源列表
	var manifest = [
		{
			src: "http://o.cztvcloud.com/181/5127659/images/bg5.jpg", id: "bg5"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/bubble.png", id: "bubble"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/fenxiang.jpg", id: "fenxiang"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/p1t1.png", id: "p1t1"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/p1t2.png", id: "p1t2"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/p1t3.png", id: "p1t3"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/p2flower.png", id: "p2flower"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/p5people.png", id: "p5people"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group1.jpg", id: "group1"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group2.jpg", id: "group2"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group3.jpg", id: "group3"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group4.jpg", id: "group4"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group5.jpg", id: "group5"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group6.jpg", id: "group6"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group7.jpg", id: "group7"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group8.jpg", id: "group8"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group9.jpg", id: "group9"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group10.jpg", id: "group10"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group11.jpg", id: "group11"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group12.jpg", id: "group12"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group13.jpg", id: "group13"
		}, {
			src: "http://o.cztvcloud.com/181/5127659/images/group14.jpg", id: "group14"
		}
	]
	// 统计加载进度
	var loadCount = 0
	preload = new createjs.LoadQueue(false, "http://o.cztvcloud.com/181/5127659/images/", false);
	// 每加载成功一个资源回调一次
	preload.on("fileload", function (event) {
		loadCount++
		console.log(loadCount);
	})
	// 所有资源加载完毕后的回调
	preload.on('complete', function (event) {
		startPaint()
		loadEnd()
	})
	preload.loadManifest(manifest)

}

function createImage(stage, id, item) {
	var image = new createjs.Bitmap(preload.getResult(id));
	image.width = item[0] * rem;
	image.height = item[1] * rem;
	image.x = -item[2] * rem;
	image.y = -item[3] * rem;
	image.alpha = 1;
	image.scale = item[4];
	image.regX = 0;
	image.regY = 0;
	stage.addChild(image)
	stage.update()
	return image
}

function startPaint() {
	var scale = [
		1, 8, 49, 348, 2000, 16000, 50000, 400000, 4200000, 24000000, 310000000, 2700000000, 14650000000, 46329491284
	]
	var item = [
		//[width,height,x,y,scale],
		[
			750, 14.48, 0, 0, scale[0]
		]
	]


	var groupsheet1 = {//创建一个动画实例
		"images"  : [preload.getResult('group1')],
		"frames"  : {
			"width" : 750,            //每个图的高度为292，宽度为165，一共有64张图
			"height": 1448,
			"count" : 6
		},
		animations: {
			"start": [0, 5, 'start', 0.1]
		}
	}
	var spriteSheet = new createjs.SpriteSheet(groupsheet1);
	var bg_am_1 = new createjs.Sprite(spriteSheet);
	bg_am_1.gotoAndPlay("start");
	bg_am_1.width = item[0][0] * rem;
	bg_am_1.height = item[0][1] * rem;
	bg_am_1.x = -item[0][2] * rem;
	bg_am_1.y = -item[0][3] * rem;
	bg_am_1.alpha = 1;
	bg_am_1.scale = item[0][4];
	bg_am_1.regX = 0;
	bg_am_1.regY = 0;
	bg_am_1.scale = canvas_scale
	stage.addChild(bg_am_1)
	stage.update()


}

function loadEnd() {
	var instance = ''
	var queue = new createjs.LoadQueue(false); //本地开发使用false即可
	queue.installPlugin(createjs.Sound);//如果载入声音，必须先注册createjs.Sound
	queue.on("complete", handleComplete, this);  //载入完成后调用
	queue.loadManifest([
		{
			id : "a2",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/b61d9682c4e04bbc9907ffb3a405bd0c/h264_128k_mp3.mp3"
		},
		{
			id : "a3",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/d966d66090154847ae204377875a6a29/h264_128k_mp3.mp3"
		},
		{
			id : "a4",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/17a40dfebc814725a88f70c5b4d086dc/h264_128k_mp3.mp3"
		},
		{
			id : "a5",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/b3dbcd20f01b401898d55c7c8e79a600/h264_128k_mp3.mp3"
		},
		{
			id : "a6",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/8d43c9fcdad849109c0265d55eea40bb/h264_128k_mp3.mp3"
		},
		{
			id : "a7",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/cf541ab440d4499680a4869b4eb6d141/h264_128k_mp3.mp3"
		},
		{
			id : "a8",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/8a4ec8e948114c73b0f2a43ec74a240d/h264_128k_mp3.mp3"
		},
		{
			id : "a9",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/97c851fbf1f54928ac4e2c978bfe3926/h264_128k_mp3.mp3"
		},
		{
			id : "a10",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/82296ab691fa4e1290573445f2ff983f/h264_128k_mp3.mp3"
		},
		{
			id : "a11",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/01fbc3d1a53944a385f228d34417aeaa/h264_128k_mp3.mp3"
		},
		{
			id : "a12",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/91c3f0dd79584d3b8608a5a49896544c/h264_128k_mp3.mp3"
		},
		{
			id : "a13",
			src: "http://v3.cztv.com/cztv/vod/2019/03/13/c527f4ea716e4f7092af9a10bbeef325/h264_128k_mp3.mp3"
		},
		{
			id : "a14",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/a31737f47d8843ce8d3047723ecbd481/h264_128k_mp3.mp3"
		},
		{
			id : "last",
			src: "http://v3.cztv.com/cztv/vod/2019/03/12/b91acf8732074d7093d4669fba6eae19/h264_128k_mp3.mp3"
		},
	]);
	instance = ''

	function handleComplete() {
		console.log('loadcomplete')
	}
}

function translateY() {
	stage.update()

}

//// -----------------------------


function throttle(fun, wait) {//节流函数
	let pre = new Date().getTime()
	return function () {
		let context = this;
		let args = arguments;
		let now = new Date().getTime()
		if ((now - pre) > wait) {
			fun.apply(context, args)
			pre = new Date().getTime()
		}
	}
}

function init() {
	var w, h
	if (IsPC()) {
		var height = window.innerHeight
		var width = height * 414 / 799
		w = 414;
		h = 666;
		var pcw = 750 * (w / 750);//rem
		var pch = 1334 * (w / 750);//
		$("html").css({
			"width"     : width,
			"margin"    : "0 auto",
			"marginTop" : "0",
			"height"    : height,
			"background": "#fff"
		});
		$("html").css({fontSize: w / 750 * 100 + "px"});
		$("html").css({minHeight: h});
	}
}

function IsPC() {
	var userAgentInfo = navigator.userAgent;
	var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
	var flag = true;
	for (var v = 0; v < Agents.length; v++) {
		if (userAgentInfo.indexOf(Agents[v]) > 0) {
			flag = false;
			break;
		}
	}
	return flag;
}

function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]);
	return null;
}

function orient() {
	if (window.orientation == 0 || window.orientation == 180) {//竖屏;//ipad、iphone竖屏；Andriod横屏
		$(".loading").hide().removeClass("hp");
		return false;
	} else if (window.orientation == 90 || window.orientation == -90) {//横屏;//ipad、iphone横屏；Andriod竖屏
		$(".loading").show().addClass("hp");
		var video = document.getElementById("video");
		video.ended();
		video.addEventListener("ended", function () {
			$("#video,.mask").hide()
		})
		$("#video").hide()
		return false;
	} else {
		$(".loading").fadeOut();
	}
}

function isAndroid() {
	var u = navigator.userAgent;
	var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
	return isAndroid
}

function bgmusicpause() {
	if (play_now) {
		$(".music_play").removeClass("music_pause");
		$(".music_play").addClass("music_pause");
		play_now = false;
		playused = true;
		$(".bgMusic")[0].pause();
		$(".music").attr("src", "https://o.cztvcloud.com/181/5842406/images/musicoff.png")
	}
}

function musicreturn() {
	if (playused) {
		$(".music_play").removeClass("music_pause");
		play_now = true;
		playused = false;
		$(".bgMusic")[0].play();
		$(".music").attr("src", "https://o.cztvcloud.com/181/5842406/images/musicon.png")
	}
}


